package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.ViewPoint;
import cn.wolfcode.trip.base.mapper.ViewPointMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IViewPointService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: Ian
 * @Date: 2019/4/16
 * @Description: cn.wolfcode.trip.base.service
 * @Version: 1.0
 */
@Service
public class IViewPointServiceImpl implements IViewPointService {
    private final ViewPointMapper mapper;

    @Autowired
    public IViewPointServiceImpl(ViewPointMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public PageInfo<ViewPoint> queryViewPoints(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        List<ViewPoint> list = mapper.selectAll(qo);
        return new PageInfo<>(list);
    }

    @Override
    public void saveOrUpdate(ViewPoint entity) {
        if(entity.getId()==null) {
           mapper.insert(entity);
        }else {
            mapper.updateByPrimaryKey(entity);
        }
    }

    @Override
    public ViewPoint get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ViewPoint> getList() {

        return mapper.list();
    }
}
